export default {
	async childCustomerAPIGetCustomerPermissionList() {
		let res = await this.httptool.post(this.apis.childCustomerAPIGetCustomerPermissionList, null);
		this.permissions = res.data.list;

	},
	async childCustomerAPIPage() {
		let res = await this.httptool.post(this.apis.childCustomerAPIPage, this.params);
		this.tableData = res.data.list;

	},
	async childCustomerAPICreateChildAccount() {
		if(!this.id) {
			let rule = [{
				name: 'loginCounter',
				label: '手机号',
				rule: ['validateTel_']
			}, {
				name: 'name',
				label: '用户名',
				rule: ['validateEmpty_']
			}, {
				name: 'pwd',
				label: '密码',
				rule: ['validatePwd']
			}, {
				name: 'confirmPwd',
				label: '确认密码',
				rule: ['validatePwd']
			}]
			if(this.info.pwd != this.info.confirmPwd) {
				this.$message('两次密码输入不一致');
				return false;
			}
			if(!this.validatetool.validate(this, this.info, rule)) {
				return;
			}
			this.info.permissionIds = this.myPermissions.join(',');
			let res = await this.httptool.post(this.apis.childCustomerAPICreateChildAccount, this.info);
			this.$message('添加成功!');
			this.info = {
				id: null,
				customerName: null,
				loginCounter: null,
				name: null,
				permissionIds: null,
				pwd: null,
				confirmPwd: null,
				idNo: null,

			};
			this.id = null;
			this.childCustomerAPIPage();
		} else {
			this.childCustomerAPIAuthorization();
		}

	},
	async childCustomerAPIUpdateState() {
		let params = {
			customerId: this.currentModelData.id,
			state: this.currentModelData.state
		}
		console.log(params.state);
		let res = await this.httptool.post(this.apis.childCustomerAPIUpdateState, params);
		if(!this.currentModelData.state) {
			this.$message('账号被禁用!');
		} else {
			this.$message.success('账号已启用!');
		}

	},
	async childCustomerAPIAuthorization() {
		let params = {
			customerId: this.id,
			permissionIds: this.myPermissions.join(',')
		}
		let res = await this.httptool.post(this.apis.childCustomerAPIAuthorization, params);
		this.$message('修改权限成功!');
		this.childCustomerAPIPage();
		this.info = {
			id: null,
			customerName: null,
			loginCounter: null,
			name: null,
			permissionIds: null,
			pwd: null,
			confirmPwd: null,
			idNo: null
		};
		this.id = null;
		this.myPermissions = [];

	},
	async childCustomerAPIDetails(id) {
		let res = await this.httptool.post(this.apis.childCustomerAPIDetails, {
			id
		});
		this.info = {
			name: res.data.realName,
			loginCounter: res.data.loginCounter,
			permissionIds: null,
			idNo: '****',
			pwd: '****',
			confirmPwd: '****'
		};
		if(res.data.customerPermissionList && res.data.customerPermissionList.length > 0) {
			this.myPermissions = res.data.customerPermissionList.map(item => item.id);
		}

	},
	checkIDlength(str, frontLen, endLen) {
		var len = str.length - frontLen - endLen;
		var xing = '';
		for(var i = 0; i < len; i++) {
			xing += '*';
		}
		return str.substring(0, frontLen) + xing + str.substring(str.length - endLen);
	}

}